<?php
/*****************切记,重名易错**************************/
include 'D:/dingjiangbbs/common/home.php';
//屏蔽notice错误
error_reporting(E_ALL ^ E_NOTICE);

var_dump($_POST);

//版块展示,批量修改版块内容,及排序
if ($_POST['button'] == '提交') {

	for ($i=0;$i<count($_POST['$cid']);$i++) {

		$cid         = $_POST['$cid'][$i];
		$orderby     = $_POST['$orderby'][$i];
		$classname   = $_POST['$classname'][$i];
		$compere     = $_POST['$compere'][$i];
		$description = $_POST['description'][$i];

		//修改数据库字段
		$table = DB_TABLE_CG;
		$data  = [
			'orderby'     => "$orderby",
			'cid'         => "$cid",
			'classname'   => "$classname",
			'compere'     => "$compere",
			'description' => '$description'
		];
		
		$where = "cid=$cid";
		$res_update = update($link,$table,$data,$where);
			
	}

	echo '<a href="'.WEB_SITE.'admin_cg.php?bighead=3&cg_number=5">修改成功</a>';

}
//判断版块当前状态,并修改.隐藏/显示
if ($_POST['button1']) {
	
	
		$cid0     = $_POST['button1'];
		//var_dump($cid0);
		
		$res_sel1 = select($link,DB_TABLE_CG,'cisdel',"where cid=$cid0");
		$cisdel1  = $res_sel1[0]['cisdel'];

		//若cisdel为1,则隐藏
		if ($cisdel == 1) {

			$data1  = [
				'cisdel' => 0
			];

			$res1   = update($link,DB_TABLE_CG,$data1,"cid=$cid0");
			//var_dump($res1);
			echo '操作成功';
			header('refresh:3;url='.WEB_SITE.'admin_cg.php?bighead=3&cg_number=5'); 
		}

		//若cisdel为0,则显示
		if ($cisdel == 0) {

			$data2  = [
				'cisdel' => 1
			];

			$res2   = update($link,DB_TABLE_CG,$data2,"cid=$cid0");
			echo '操作成功';
			header('refresh:3;url='.WEB_SITE.'admin_cg.php?bighead=3&cg_number=5');
		}	
	
}	


//判断版块当前状态,并修改.隐藏/显示
if ($_POST['button2']) {

		//伪删除
	$cid2   = $_POST['button2'];
	//var_dump($cid2);

	$res_sel2 = select($link,DB_TABLE_CG,'cisdel',"where cid=$cid2");
	$cisdel2  = $res_sel2[0]['cisdel'];

		//删除过程
	if ($cisdel2 < 2){

		$data3  = [
			'cisdel' => 2
		];

		$res2  = update($link,DB_TABLE_CG,$data3,"cid=$cid2");
		//var_dump($res2); 
		echo '操作成功';
		header('refresh:3;url='.WEB_SITE.'admin_cg.php?bighead=3&cg_number=5');

	}	

	//取消删除过程
	if ($cisdel2 == 2) {
		$data4  = [
			'cisdel' => 0
		];

		$res4  = update($link,DB_TABLE_CG,$data4,"cid=$cid2");
		//var_dump($res4); 
		echo '操作成功';
		header('refresh:3;url='.WEB_SITE.'admin_cg.php?bighead=3&cg_number=5');
	}	
}

